import random

class Gradeone(): #基本上思路就是先做算术的确定，再确定数字最后输出
    def __init__(self):
        self.score = 0
        self.symbol= 0 #存放符号，1表示加法,2表示减法
        self.num1 = 0 #存放数字
        self.num2 = 0
    
    def symbolgeneration(self):
        self.symbol = random.randint(1,2)
    
    def numbergeneration(self):
        a = random.randint(1,99)   #尽量保证a比b大
        b = random.randint(1,99)
        if self.symbol == 2:
            if a < b:
                z = 0
                z = a
                a = b
                b = z
        self.num1 = a
        self.num2 = b
    
    def checking(self):
        if self.symbol == 1:
            rightans = self.num1 + self.num2
            ans = input(str(self.num1)+"+"+str(self.num2)+"=")
            ans = int(ans) #一个小bug,当输入的不是数字的时候会停止
            if ans == rightans:
                print("很棒，你做对了这道题")
                self.score += 3.33
            else:
                print("噢哦，再接再厉")
        else:
            rightans = self.num1 - self.num2
            ans = input(str(self.num1)+"-"+str(self.num2)+"=")
            ans = int(ans) #一个小bug,当输入的不是数字的时候会停止
            if ans == rightans:
                print("很棒，你做对了这道题")
                self.score += 3.33
            else:
                print("噢哦，再接再厉")
        return None
    
    def mainfunc(self):
        print("每天30题的口算练习哦")
        get = input("如果准备好了就输入yes开始吧\n")
        while(not get == "yes"):
            get = input("输入yes开始\n")
        
        for i in range(30):
            print("第"+str(i+1)+"道口算练习")
            self.symbolgeneration()
            self.numbergeneration()
            self.checking()
        final = int(self.score+0.5)
        print("你的最终分数是"+str(final))
        if self.score >= 90:
            print("非常不错，你是数学天才小高斯")
        elif self.score >=80:
            print("很好，你很有数学天赋，还可以再加把劲")
        elif self.score >= 70:
            print("多多努力你也会变得更强")
        else:
            print("看来要好好修炼计算能力了啊")
        return None
        
class Gradetwo(): #与grade1不同的是，此处的操作数可以为2，3任意，并且加入了乘法和除法,并且出现()+4+8-9 = 15这样的题，仅限于加减
    def __init__(self):
        self.problemtype = 0 #存放problemtype,1表示普通的算术计算题，2表示()加减题目
        self.amoofnums = 0 #用于存放数字总数
        self.score = 0
        self.symbol1= 0 #存放符号，1表示加法,2表示减法，3表示加法，4表示减法
        self.symbol2= 0
        self.symbol3= 0
        self.num1 = 0 #存放数字,其实想用栈的，但是出现了点bug
        self.num2 = 0
        self.num3 = 0
        self.num4 = 0
    
    def problemtypegeneraion(self):
        self.problemtype = random.randint(1,2)
    
    def amoofnumsgeneration(self):
        self.amoofnums = random.randint(2,4)

    def symbolgeneration(self):
        if self.problemtype == 1:
            self.symbol1 = random.randint(1,4)
            self.symbol2 = random.randint(1,3)
        else: #如果是第二种题目只有加减法
            self.symbol1 = random.randint(1,2)
            self.symbol2 = random.randint(1,2)
    
    def numbergeneration(self):
        self.num1 = random.randint(1,99)
        self.num2 = random.randint(1,99)
        if self.num1 < self.num2:
            z = 0
            z = self.num1
            self.num1 = self.num2
            self.num2 = z
        self.num3 = self.num1 * random.randint(2,9)
        self.num4 = self.num2 * random.randint(2,9)
        
    
    def checking(self):
        if self.problemtype == 1:
            problemt2 = random.randint(1,3)
            if self.amoofnums == 2:
                if self.symbol1 == 1:
                    rightans = self.num1 + self.num2
                    if problemt2 == 1:
                        k=random.randint(1,99)
                        ref = self.num1+k
                        ans = input(str(ref)+"-"+"("+str(k)+"+"+str(self.num2)+")"+"=")
                    else:
                        k = random.randint(2,9)
                        ref = k*self.num2
                        ans = input(str(self.num1)+"+"+str(ref)+"÷"+str(k)+"=")
                    ans = int(ans) #一个小bug,当输入的不是数字的时候会停止
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 2:
                    rightans = self.num1 - self.num2
                    if problemt2 == 1:
                        k = random.randint(1,self.num2)
                        ref = self.num2-k
                        ans = input(str(self.num1)+"-"+"("+str(ref)+"+"+str(k)+")"+"=")
                    else:
                        k = random.randint(2,9)
                        ref = k*self.num2
                        ans = input(str(self.num1)+"-"+str(ref)+"÷"+str(k)+"=")
                    ans = int(ans) #一个小bug,当输入的不是数字的时候会停止
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 3:
                    rightans = self.num1 * self.num2
                    if problemt2 == 1:
                        ans = input(str(self.num1)+"x"+str(self.num2)+"=")
                    elif problemt2 == 2:
                        k = random.randint(1,self.num2)
                        ref = self.num2-k
                        ans = input(str(self.num1)+"x"+"("+str(ref)+"+"+str(k)+")"+"=")
                    else:
                        k = random.randint(1,99)
                        ref = self.num2+k
                        ans = input(str(self.num1)+"x"+"("+str(ref)+"-"+str(k)+")"+"=")
                    ans = int(ans) #一个小bug,当输入的不是数字的时候会停止
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                else: # self.symbol1 == 4
                    rightans = self.num3/self.num1
                    if problemt2 == 1:
                        ans = input(str(self.num3)+"÷"+str(self.num1)+"=")
                    elif problemt2 == 2:
                        k = random.randint(1,self.num2)
                        ref = self.num1-k
                        ans = input(str(self.num1)+"÷"+"("+str(ref)+"+"+str(k)+")"+"=")
                    else:
                        k = random.randint(1,99)
                        ref = self.num1+k
                        ans = input(str(self.num1)+"÷"+"("+str(ref)+"-"+str(k)+")"+"=")
                    ans = int(ans) #一个小bug,当输入的不是数字的时候会停止
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
            elif self.amoofnums == 2:
                if self.symbol1 == 1 and self.symbol2 == 1:
                    num5 = random.randint(1,99)
                    rightans = self.num1+self.num2+num5
                    ans = input(str(self.num1)+"+"+str(self.num2)+"+"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 1 and self.symbol2 == 2:
                    num5 = random.randint(1,self.num1+self.num2)
                    rightans = self.num1+self.num2+self.num2-num5
                    ans = input(str(self.num1)+"+"+str(self.num2)+"-"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 1 and self.symbol2 == 3:
                    num5 = random.randint(2,9)
                    rightans = self.num1+self.num2*num5
                    ans = input(str(self.num1)+"+"+str(self.num2)+"x"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 2 and self.symbol2 == 1:
                    num5 = random.randint(1,99)
                    rightans = self.num1-self.num2+num5
                    ans = input(str(self.num1)+"-"+str(self.num2)+"+"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 2 and self.symbol2 == 2:
                    num5 = random.randint(0,99)
                    rightans = self.num1-self.num2+num5
                    ans = input(str(self.num1)+"-"+str(self.num2)+"+"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 2 and self.symbol2 == 3:
                    num5 = random.randint(1,self.num1//self.num2)
                    rightans = self.num1-self.num2*num5
                    ans = input(str(self.num1)+"-"+str(self.num2)+"x"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 3 and self.symbol2 == 1:
                    num5 = random.randint(2,9)
                    rightans = self.num1 * num5+ self.num2
                    ans = input(str(self.num1)+"x"+str(self.num2)+"+"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 3 and self.symbol2 == 2:
                    num5 = random.randint(2,9)
                    rightans = self.num1*num5-self.num2
                    ans = input(str(self.num1)+"x"+str(self.num2)+"-"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 3 and self.symbol2 == 3:
                    num5 = random.randint(2,9)
                    rightans = self.num1*num5*self.num2
                    ans = input(str(self.num1)+"x"+str(self.num2)+"x"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 4 and self.symbol2 == 1:
                    num5 = random.randint(1,99)
                    rightans = self.num3/self.num1+num5
                    ans = input(str(self.num3)+"÷"+str(self.num1)+"+"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 4 and self.symbol2 == 2:
                    num5 = random.randint(10,99)
                    rightans = num5-self.num3/self.num1
                    ans = input(str(num5)+"-"+str(self.num3)+"÷"+str(self.num1)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
                elif self.symbol1 == 4 and self.symbol2 == 3:
                    num5 = random.randint(1,99)
                    rightans = self.num3/self.num1*num5
                    ans = input(str(self.num3)+"÷"+str(self.num1)+"x"+str(num5)+"=")
                    ans = int(ans)
                    if ans == rightans:
                        print("很棒，你做对了这道题")
                        self.score += 3.33
                    else:
                        print("噢哦，再接再厉")
        else:
            print("还没编写完全部功能")
            
    
    def mainfunc(self):
        print("每天30题的口算练习哦")
        get = input("如果准备好了就输入yes开始吧\n")
        while(not get == "yes"):
            get = input("输入yes开始\n")
        
        for i in range(30):
            print("第"+str(i+1)+"道口算练习")
            self.problemtypegeneraion()
            self.amoofnumsgeneration()
            self.symbolgeneration()
            self.numbergeneration()
            self.checking()
        final = int(self.score+0.5)
        print("你的最终分数是"+str(final))
        if self.score >= 90:
            print("非常不错，你是数学天才小高斯")
        elif self.score >=80:
            print("很好，你很有数学天赋，还可以再加把劲")
        elif self.score >= 70:
            print("多多努力你也会变得更强")
        else:
            print("看来要好好修炼计算能力了啊")
        return None

if __name__ == "__main__":
    print("欢迎使用家长帮出题系统，本系统提提供小学算术题的出题并改错。家长帮努力加载中")
    grade = input("请选择目前的年级:(输入1为一年级,2为二年级,3为三年级,4为四年级)\n") 
    #这边的想法是图形界面直接点击选择
    while(not(grade == "1" or grade == "2" or grade == "3")):
        print("输入不正确哦，再试一次吧")
        grade = input("请选择目前的年级:(输入1为一年级,2为二年级,3为三年级,4为四年级)\n") 
    if grade=="1":
        gradeone = Gradeone()
        gradeone.mainfunc()
    elif grade == "2":
        gradetwo = Gradetwo()
        gradetwo.mainfunc()
    else:
        print("还没编写完全部功能")
    











